package chapter18;

/**
 * @Author：xz
 * @Date：2023/9/14
 */
public class MyStack {
    private Object[] elements = new Object[10];

    private int index = -1;

    public Object[] getElements() {
        return elements;
    }

    public void setElements(Object[] elements) {
        this.elements = elements;
    }

    public void push(Object obj) {
        Object[] elements = this.getElements();
        if (index >= elements.length-1) {
            System.out.println("栈满");
        }
        elements[++index] = obj;
    }

    public Object pop() {
        if (index < 0) {
            System.out.println("栈空");
            return null;
        }
        Object[] elements = this.getElements();
        Object element = elements[index];
        elements[index--] = null;
        return element;
    }
}
